Completed
Branch future (3a58b6)
by Xaver
34s
created

main.js ➔ ... ➔ setData   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
nc 4
dl 0
loc 8
rs 9.4285
nop 1
1
define(['infobox/link', 'infobox/node', 'infobox/location'], function (Link, Node, location) {
2
  'use strict';
3
4
  return function (config, sidebar, router, linkScale) {
5
    var self = this;
6
    var el;
7
    var node;
8
    var link;
9
10
    function destroy() {
11
      if (el && el.parentNode) {
12
        el.parentNode.removeChild(el);
13
        el = undefined;
14
        sidebar.reveal();
15
      }
16
    }
17
18
    function create() {
19
      destroy();
20
      sidebar.ensureVisible();
21
      sidebar.hide();
22
23
      el = document.createElement('div');
24
      sidebar.container.children[1].appendChild(el);
25
26
      el.scrollIntoView(false);
27
      el.classList.add('infobox');
28
      el.destroy = destroy;
29
30
      var closeButton = document.createElement('button');
31
      closeButton.classList.add('close');
32
      closeButton.classList.add('ion-close');
33
      closeButton.onclick = function () {
34
        router.fullUrl();
35
      };
36
      el.appendChild(closeButton);
37
    }
38
39
    self.resetView = destroy;
40
41
    self.gotoNode = function gotoNode(d, gateways) {
42
      create();
43
      node = new Node(config, el, router, d, linkScale, gateways);
44
      node.render();
45
    };
46
47
    self.gotoLink = function gotoLink(d) {
48
      create();
49
      link = new Link(config, el, router, d, linkScale);
50
      link.render();
51
    };
52
53
    self.gotoLocation = function gotoLocation(d) {
54
      create();
55
      location(config, el, router, d);
56
    };
57
58
    self.setData =  function setData(d) {
59
      if (typeof node === 'object') {
60
        node.setData(d);
61
      }
62
      if (typeof link === 'object') {
63
        link.setData(d);
64
      }
65
    };
66
67
68
    return self;
69
  };
70
});
71